package com.twu.biblioteca.storage;

import com.twu.biblioteca.*;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by MDH on 20/07/2014.
 */
public class StorageServiceInMemoryImpl implements StorageService{

    public List<Book> booksList = new ArrayList<Book>();

    //TODO this is dummy data for the purpose of running the application
    public static final Book B_1 = new BookImpl("Harry Potter 1", "JK Rowling", "1995", true);
    public static final Book B_2 = new BookImpl("Harry Potter 2", "JK Rowling", "1996", false);
    public static final Book B_3 = new BookImpl("Harry Potter 3", "JK Rowling", "1997", true);
    public static final Book B_4 = new BookImpl("Harry Potter 4", "JK Rowling", "1998", true);
    public static final Book B_5 = new BookImpl("Harry Potter 5", "JK Rowling", "1999", true);
    public static final Book B_6 = new BookImpl("Harry Potter 6", "JK Rowling", "2000", true);
    public static final Book B_7 = new BookImpl("Harry Potter 7", "JK Rowling", "2001", true);
    public static final Book B_8 = new BookImpl("Daughter of the Empire", "Raymond E Fiest", "1995", true);

    //TODO this is dummy data for the purpose of running the application
    public static final Movie M_1 = new MovieImpl("Harry Movie 1", "JK Rowling", "1995", 10, true);
    public static final Movie M_2 = new MovieImpl("Harry Movie 2", "JK Rowling", "1996", 9, false);
    public static final Movie M_3 = new MovieImpl("Harry Movie 3", "JK Rowling", "1997", 8, true);
    public static final Movie M_4 = new MovieImpl("Harry Movie 4", "JK Rowling", "1998", 7, true);
    public static final Movie M_5 = new MovieImpl("Harry Movie 5", "JK Rowling", "1999", -1,true);
    public static final Movie M_6 = new MovieImpl("Harry Movie 6", "JK Rowling", "2000", 2, true);
    public static final Movie M_7 = new MovieImpl("Harry Movie 7", "JK Rowling", "2001", 10, true);
    public static final Movie M_8 = new MovieImpl("Daughter of the Movie", "Raymond E Fiest", "1995", 5, true);

    private boolean checkedIn;

    public List<Movie> movieList = new ArrayList<Movie>();
    private List<UserAccount> userAccountList = new ArrayList<UserAccount>();

    //TODO this is dummy data for the purpose of running the application
    public static final UserAccount U_1 = new UserAccountImpl("111-1111", "Name", "Email", "Phone", "Password");

    //TODO This is a dummy set of data for the purpose of running the applications
    public StorageServiceInMemoryImpl(){
        booksList.add(B_1);
        booksList.add(B_2);
        booksList.add(B_3);
        booksList.add(B_4);
        booksList.add(B_5);
        booksList.add(B_6);
        booksList.add(B_7);
        booksList.add(B_8);

        movieList.add(M_1);
        movieList.add(M_2);
        movieList.add(M_3);
        movieList.add(M_4);
        movieList.add(M_5);
        movieList.add(M_6);
        movieList.add(M_7);
        movieList.add(M_8);

        userAccountList.add(U_1);
    }

    @Override
    public List<Book> getBooksList() {
        return booksList;
    }

    @Override
    public String bookToPrint(int index) {
        Book bookToPrint = booksList.get(index);
        String toPrint = bookToPrint.getBookTitle() + " - " + bookToPrint.getBookAuthor() + " - " + bookToPrint.getBookYear();
        return toPrint;
    }

    @Override
    public String printAllBooks() {
        String allBooksToPrint = "";
        for(int i =0; i<booksList.size(); i++){
            allBooksToPrint = allBooksToPrint + bookToPrint(i) + "\n";
        }
        return allBooksToPrint;
    }

    @Override
    public String printCheckedInBooks() {
        String checkedInBooksToPrint = "";
        for(int i =0; i<booksList.size(); i++){
            checkedIn = booksList.get(i).isCheckedIn();
            if(checkedIn){
                checkedInBooksToPrint = checkedInBooksToPrint + bookToPrint(i) + "\n";
            }

        }
        return checkedInBooksToPrint;
    }

    @Override
    public void toPrintFormatted() {
        for(int i =0; i<booksList.size(); i++){
            Book book = booksList.get(i);
            if(book.isCheckedIn()){
                book.toPrint();
            }

        }
    }

    @Override
    public List<Movie> getMoviesList() {

        return movieList;
    }

    @Override
    public void toPrintMoviesFormatted() {
        for(int i =0; i<movieList.size(); i++){
            Movie movie = movieList.get(i);
            if(movie.isCheckedIn()){
                movie.toPrint();
            }

        }
    }

    @Override
    public List<UserAccount> getUserAccountList() {
        return userAccountList;
    }
}
